package com.example.itshome.util;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class TimeUtil {

    public static final String SUNDAY = "星期日";

    /**
     * 星期一;
     */
    public static final String MONDAY = "星期一";

    /**
     * 星期二;
     */
    public static final String TUESDAY = "星期二";

    /**
     * 星期三;
     */
    public static final String WEDNESDAY = "星期三";

    /**
     * 星期四;
     */
    public static final String THURSDAY = "星期四";

    /**
     * 星期五;
     */
    public static final String FRIDAY = "星期五";

    /**
     * 星期六;
     */
    public static final String SATURDAY = "星期六";

    public static String format(Date temporal, String pattern) {
        SimpleDateFormat format=new SimpleDateFormat(pattern,Locale.CHINA);
        format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return format.format(temporal);
    }

    public static String getDayOfWeekStr(LocalDate localDate) {
        String[] weekOfDays = {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};
        int dayOfWeek = localDate.getDayOfWeek().getValue() - 1;
        return weekOfDays[dayOfWeek];
    }

    public static String getMonthStr(LocalDate localDate) {
        String[] monthOfYears = {"一月", "二月", "三月", "四月", "五月", "六月", "七月","八月","九月","十月","十一月","十二月"};
        int month = localDate.getMonth().getValue()-1;
        return monthOfYears[month];
    }

}
